package com.wc.alorithm_luogu._前缀和与差分.DlgtArray;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/11/10 14:37
 * @description
 * https://www.luogu.com.cn/problem/T530603?contestId=127930
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 1000010;
    static int[] a = new int[N], s = new int[N];
    static int n, q, l, r, k;

    public static void main(String[] args) {
        n = sc.nextInt();
        q = sc.nextInt();
        for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
        for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];
        while (q-- > 0){
            l = sc.nextInt();
            r = sc.nextInt();
            k = sc.nextInt();
            int sum = s[r] - s[l - 1];
            if (sum == k){
                if (sum < r - l + 1) out.println(0);
                else out.println(-1);
            } else if (sum < k) {
                if (k  >= r - l + 1) out.println(-1);
                else out.println(k - sum);
            } else {
                if (sum == k + (sum == r - l + 1 ? 1 : 0)) out.println(0);
                else out.println(sum - k);
            }
        }
        out.flush();
    }

}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
